﻿using System;
namespace ETRC.CommLib
{
    using System.IO.Ports;
    using System.Collections.Generic;

    /// <summary>
    /// interface for Communication send/receive logger
    /// </summary>
    public interface CommLogWriter
    {
        void StoreSendData(DateTime timestamp, byte[] data, int offset, int length);
        void StoreReceivedData(DateTime timestamp, byte[] data, int offset, int length);
    }

    /// <summary>
    /// interface for resolver of synchronous communication response
    /// </summary>
    public interface ResponseDataResolver
    {
        void IsValidResponse(byte[] response, out bool isResponse, out bool isDone);
    }

    /// <summary>
    /// interface for Data Exchange Manager to send/receive data via virtual COM port.
    /// </summary>
    public interface IDataExchangeManager
    {
        SerialPort CurrentPort { get; }
        CommLogWriter LogWriter { get; set; }

        void Start();
        void Stop();

        byte[] GetReceiveData();
        void SendData(byte[] buf, int offset, int count);
        void SendData(string data);
        void SendSyncData(byte[] buf, int offset, int count,
            List<byte[]> response, ResponseDataResolver resolver = null);
        void SendSyncData(string buf, List<byte[]> response,
            ResponseDataResolver resolver = null);
    }
}
